#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
# @version: v1.0
# @author : wlisingle
# @Email : 19688513@qq.com
# @Project : g-carbon-bio
# @File : stock_trade.py
# @Software: PyCharm
# @time: 2025/2/18 9:07
# @description : 连表查询 stockBase 和stockTradeBase
"""
from service.models.stock_base import StockBase
from service.models.stock_trade_base import StockTradeBase


class StockTrade(StockTradeBase, StockBase):
    def __init__(self, stock_id: int, s_code: str, t_rate: float, v_ratio: float,
                 o_disk: float, i_disk: float, name: str, latest_price: float,
                 change_percent: float, change_amount: float, volume: float, turnover: float,
                 amplitude: float, high: float, low: float, open_price: float, prev_close: float,
                 volume_ratio: float, turnover_rate: float, dynamic_pe_ratio: float,
                 pb_ratio: float, total_market_value: float, circulating_market_value: float,
                 increase_speed: float, five_minute_change: float, sixty_day_change: float,
                 year_to_date_change: float, industry: str, amplitudes: float,
                 volume_ratio_yesterday: float = None, volume_ratio_day_before_yesterday: float = None,
                 creation_time=None, rating: str = None, total_net_inflow_positive: float = 0,
                 total_net_inflow_negative: float = 0):
        """
        股票交易类，继承自 StockTradeBase 和 StockBase。

        Args:
            stock_id (int): 股票的唯一标识符
            s_code (str): 股票代码
            t_rate (float): 换手率
            v_ratio (float): 量比
            o_disk (float): 外盘
            i_disk (float): 内盘
            name (str): 股票名称
            latest_price (float): 最新价
            change_percent (float): 涨跌幅
            change_amount (float): 涨跌额
            volume (float): 成交量
            turnover (float): 成交额
            amplitude (float): 振幅
            high (float): 最高价
            low (float): 最低价
            open_price (float): 今开盘价
            prev_close (float): 昨收盘价
            volume_ratio (float): 量比
            turnover_rate (float): 换手率
            dynamic_pe_ratio (float): 市盈率-动态
            pb_ratio (float): 市净率
            total_market_value (float): 总市值
            circulating_market_value (float): 流通市值
            increase_speed (float): 涨速
            five_minute_change (float): 5分钟涨跌
            sixty_day_change (float): 60日涨跌幅
            year_to_date_change (float): 年初至今涨跌幅
            industry (str): 行业
            amplitudes (float): 振幅
            volume_ratio_yesterday (float): 昨天成交量倍数（可选）
            volume_ratio_day_before_yesterday (float): 前天成交量倍数（可选）
            creation_time: 创建时间（可选）
            rating (str): 股票评级（可选）
            total_net_inflow_positive (float): 正净流入总和（可选）
            total_net_inflow_negative (float): 负净流入总和（可选）
        """
        StockTradeBase.__init__(self, stock_id, s_code, t_rate, v_ratio, o_disk, i_disk, creation_time)
        StockBase.__init__(self, stock_id, s_code, name, latest_price, change_percent, change_amount,
                           volume, turnover, amplitude, high, low, open_price, prev_close,
                           volume_ratio, turnover_rate, dynamic_pe_ratio, pb_ratio, total_market_value,
                           circulating_market_value, increase_speed, five_minute_change, sixty_day_change,
                           year_to_date_change, creation_time)

        self._industry = industry
        self._amplitudes = amplitudes
        self._volume_ratio_yesterday = volume_ratio_yesterday
        self._volume_ratio_day_before_yesterday = volume_ratio_day_before_yesterday
        self._rating = rating  # 股票评级
        self._total_net_inflow_positive = total_net_inflow_positive  # 正净流入总和
        self._total_net_inflow_negative = total_net_inflow_negative  # 负净流入总和

    @property
    def industry(self) -> str:
        """获取行业属性"""
        return self._industry

    @industry.setter
    def industry(self, value: str):
        """设置行业属性"""
        self._industry = value

    @property
    def amplitudes(self) -> float:
        """获取振幅属性"""
        return self._amplitudes

    @amplitudes.setter
    def amplitudes(self, value: float):
        """设置振幅属性"""
        self._amplitudes = value

    @property
    def volume_ratio_yesterday(self) -> float:
        """获取昨天成交量倍数"""
        return self._volume_ratio_yesterday

    @volume_ratio_yesterday.setter
    def volume_ratio_yesterday(self, value: float):
        """设置昨天成交量倍数"""
        self._volume_ratio_yesterday = value

    @property
    def volume_ratio_day_before_yesterday(self) -> float:
        """获取前天成交量倍数"""
        return self._volume_ratio_day_before_yesterday

    @volume_ratio_day_before_yesterday.setter
    def volume_ratio_day_before_yesterday(self, value: float):
        """设置前天成交量倍数"""
        self._volume_ratio_day_before_yesterday = value

    @property
    def rating(self) -> str:
        """获取股票评级"""
        return self._rating

    @rating.setter
    def rating(self, value: str):
        """设置股票评级"""
        self._rating = value

    def __str__(self) -> str:
        """
        返回 StockTrade 对象的字符串表示
        """
        # 计算净值
        net_value = self._total_net_inflow_positive + self._total_net_inflow_negative
        return (f"股票代码: {self.s_code}, 名称: {self.name}, 最新价: {self.latest_price}, "
                f"涨跌幅: {self.change_percent}%, 换手率: {self.t_rate}%, "
                f"量比: {self.v_ratio}, 外盘: {self.o_disk}, 内盘: {self.i_disk}, "
                f"成交量: {self.volume}, 行业: {self.industry}, "
                f"评级: {self.rating}, "
                f"昨成交量倍数: {self.volume_ratio_yesterday}, 前天成交量倍数: {self.volume_ratio_day_before_yesterday}, "
                f"净值: {net_value}")

